﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KnowledgeAssistant
{
    public partial class EditTeacherForm : Form
    {
        private Teacher t = null;

        public EditTeacherForm()
        {
            InitializeComponent();
            this.Text = "Добавление нового преподавателя";
        }

        public EditTeacherForm(Teacher teacher)
        {
            InitializeComponent();
            button2.Text = "Изменить";
            this.Text = "Изменить инфо о пользователе";
            this.t = teacher;
            lname.Text = t.LastName;
            fname.Text = t.FirstName;
            mname.Text = t.MiddleName;
        }

        private void EditTeacherForm_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string lastname = lname.Text.Trim();
            string firstname = fname.Text.Trim();
            string middlename = mname.Text.Trim();
            int id = 0;
            if (t != null)
            {
                id = t.TeacherID;
            }
            if (!TeachersForm.checkExistTeacherFullName(lastname, firstname, middlename))
            {
                t = new Teacher(id, lastname, middlename, firstname);
                TeacherUtil.SaveTeacher(t);
                this.Close();
            }
            else
            {
                DialogResult dr = MessageBox.Show("Такой преподаватель уже присутствует в списке. Допустить совпадение имен?", "Совпадение имен", MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    t = new Teacher(id, lastname, middlename, firstname);
                    TeacherUtil.SaveTeacher(t);
                    this.Close();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
